package Operator;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class BorrowedOperator implements IOPerator{

    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入你要借的书的名字");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int bookcount = bookList.getListsize();
        for (int i = 0; i < bookcount; i++) {
            Book book = bookList.get_book(i);
            if(book.getName().equals(name)){
               if(book.isBorrow()){
                   System.out.println("这本书已经被借走");
                   return;
               }else{
                   book.setBorrow(true);
                   System.out.println("借阅成功");
                   return;
               }
            }
        }
        System.out.println("没有这本书");
    }
}
